package Dao;

import Table.Book;
import Utils.DruidUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UpdateBookDao {
    public static void Update(Book book) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = DruidUtils.getConnection();
            String sql = "update book set bookname=? , auther=? , " +
                    "price=? , nums=? where id = ?";
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, book.getBookname());
            pstmt.setString(2, book.getAuther());
            pstmt.setInt(3, book.getPrice());
            pstmt.setInt(4, book.getNums());
            pstmt.setInt(5, book.getId());
            int i = pstmt.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DruidUtils.close(pstmt, conn);
        }
    }
}
